import { req_login } from '../api/registerLogin'
import { Message } from "element-ui";
export default {
    async go_login({ commit }, { user_name, password, routerDL }) {
        console.log(user_name, password, routerDL);
        let result = await req_login({
            method: 'post',
            url: '/login',
            arg: {
                user_name,
                password
            },
            headerType: 'form'
        });

        if (result.data.info == '登录成功！！') {
            // 如果result.data.info=='成功'，就跳转home页
            Message({
                type: "success",
                message: "登录成功",
            });
            routerDL.push({
                name: 'home',
            })
        } else {
            Message({
                type: "error",
                message: "用户名或者密码错误，请重新输入",
            });
        }
        console.log(result);
        // 通过mutations的commit触发来更改state数据，需要传递参数user_name
        // info token
        commit('login', { user_name, info: result.data.info, token: result.data.token })
        console.log(commit);
    }
}